<template>
  <view class="container">
    <!-- 商品列表 -->
    <view class="card">
      <view class="goods-item" v-for="(item, index) in goodsList" :key="index">
        <view class="goods-info">
          <text class="goods-name">{{ item.name }}</text>
          <text class="goods-level">({{ item.level }})</text>
          <text class="goods-price">￥{{ item.price }}</text>
        </view>
        <text class="goods-count">x{{ item.count }}</text>
      </view>
    </view>

    <!-- 金额汇总 -->
    <view class="card">
      <view class="amount-item">
        <text>订单金额</text>
        <text>¥1230.00</text>
      </view>
      <view class="amount-item">
        <text>优惠折扣</text>
        <text>-¥0.00</text>
      </view>
      <view class="total-amount">
        <text>需支付：</text>
        <text class="price">￥1500.00</text>
      </view>
    </view>

    <!-- 支付方式 -->
    <view class="card">
      <view class="section-title">支付方式</view>
      
      <view class="payment-item" @click="selectPayment('wechat')">
        <u-checkbox 
          v-model="payment.wechat" 
          shape="circle"
          active-color="#07C160"
        ></u-checkbox>
        <view class="payment-info">
          <image src="/static/images/wechat-pay.png" class="payment-icon"></image>
          <text>微信支付</text>
        </view>
      </view>
      
      <view class="payment-item" @click="selectPayment('other')">
        <u-checkbox 
          v-model="payment.other" 
          shape="circle"
          active-color="#07C160"
        ></u-checkbox>
        <view class="payment-info">
          <image src="/static/images/bank-transfer.png" class="payment-icon"></image>
          <text>其他方式转账（上传转账凭证）</text>
        </view>
      </view>
      
      <!-- 上传凭证区域 -->
      <view class="upload-area" v-if="payment.other">
        <u-upload
          :fileList="fileList"
          @afterRead="afterRead"
          @delete="deletePic"
          name="1"
          multiple
          :maxCount="1"
          previewFullImage
        >
          <view class="upload-btn">
            <u-icon name="plus" size="40" color="#999"></u-icon>
            <text>上传转账凭证</text>
          </view>
        </u-upload>
      </view>
    </view>

    <!-- 底部支付按钮 -->
    <view class="footer">
      <u-button 
        type="primary" 
        shape="circle" 
        @click="confirmPayment"
        :disabled="!payment.wechat && !payment.other"
      >
        确认支付
      </u-button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      goodsList: [
        { name: '考证名称超行省略...', level: '三级', price: '123.00', count: 2 },
        { name: '考证名称超行省略...', level: '四级', price: '123.00', count: 10 },
        { name: '培训', level: '三级', price: '123.00', count: 2 },
        { name: '培训', level: '四级', price: '123.00', count: 2 }
      ],
      payment: {
        wechat: false,
        other: true
      },
      fileList: []
    }
  },
  methods: {
    selectPayment(type) {
      // 单选逻辑
      if (type === 'wechat') {
        this.payment.wechat = true
        this.payment.other = false
      } else {
        this.payment.wechat = false
        this.payment.other = true
      }
    },
    // 图片上传相关方法
    afterRead(event) {
      // 这里处理图片上传逻辑
      const { file } = event
      this.fileList.push({
        url: file.url,
        status: 'uploading',
        message: '上传中'
      })
      
      // 模拟上传成功
      setTimeout(() => {
        this.fileList[this.fileList.length - 1].status = 'success'
        this.fileList[this.fileList.length - 1].message = ''
      }, 1000)
    },
    deletePic(event) {
      this.fileList.splice(event.index, 1)
    },
    confirmPayment() {
      if (this.payment.other && this.fileList.length === 0) {
        uni.showToast({
          title: '请上传转账凭证',
          icon: 'none'
        })
        return
      }
      
      uni.showLoading({
        title: '支付处理中...'
      })
      
      // 模拟支付请求
      setTimeout(() => {
        uni.hideLoading()
        if (this.payment.wechat) {
          // 微信支付逻辑
          uni.showToast({
            title: '微信支付成功',
            icon: 'success'
          })
        } else {
          // 转账支付逻辑
          uni.showToast({
            title: '转账凭证已提交，请等待审核',
            icon: 'success'
          })
        }
        
        // 支付成功后跳转
        setTimeout(() => {
          uni.redirectTo({
            url: '/pages/order/result'
          })
        }, 1500)
      }, 2000)
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  padding: 20rpx;
  padding-bottom: 120rpx;
  background-color: #f7f7f7;
  min-height: 100vh;
}

.card {
  background-color: #fff;
  border-radius: 12rpx;
  padding: 24rpx;
  margin-bottom: 20rpx;
  box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.05);
}

.goods-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f5f5f5;
  
  &:last-child {
    border-bottom: none;
  }
}

.goods-info {
  flex: 1;
  display: flex;
  align-items: center;
  overflow: hidden;
}

.goods-name {
  font-size: 28rpx;
  color: #333;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 40%;
}

.goods-level {
  font-size: 24rpx;
  color: #999;
  margin: 0 10rpx;
}

.goods-price {
  font-size: 26rpx;
  color: #ff4d4f;
}

.goods-count {
  font-size: 26rpx;
  color: #666;
}

.amount-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 16rpx;
  font-size: 26rpx;
  color: #666;
}

.total-amount {
  display: flex;
  justify-content: flex-end;
  margin-top: 20rpx;
  font-size: 28rpx;
  font-weight: bold;
  
  .price {
    color: #ff4d4f;
    margin-left: 10rpx;
  }
}

.section-title {
  font-size: 28rpx;
  font-weight: bold;
  margin-bottom: 20rpx;
}

.payment-item {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #f5f5f5;
  
  &:last-child {
    border-bottom: none;
  }
}

.payment-info {
  display: flex;
  align-items: center;
  margin-left: 20rpx;
  font-size: 26rpx;
}

.payment-icon {
  width: 40rpx;
  height: 40rpx;
  margin-right: 15rpx;
}

.upload-area {
  margin-top: 20rpx;
  padding-top: 20rpx;
  border-top: 1rpx dashed #eee;
}

.upload-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 200rpx;
  height: 200rpx;
  background-color: #f7f7f7;
  border-radius: 8rpx;
  color: #999;
  font-size: 24rpx;
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20rpx;
  background-color: #fff;
  box-shadow: 0 -2rpx 8rpx rgba(0, 0, 0, 0.05);
  
  /deep/ .u-btn {
    height: 80rpx;
    font-size: 30rpx;
  }
}
</style>